package com.core.family.admin.service.Impl;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.core.common.gen.BaseServiceImpl;
import com.core.family.admin.domain.po.SysDict;
import com.core.family.admin.mapper.SysDictMapper;
import com.core.family.admin.service.SysDictService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qcloud.cos.utils.Jackson;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * @author honglei
 * @version 1.0
 * @time: 2022-6-10 11:46:34
 * @Description 服务实现层
 */
@Service
public class SysDictServiceImpl extends BaseServiceImpl<SysDictMapper, SysDict> implements SysDictService {


    @Override
    public List<SysDict> selectDataByname() {
        QueryWrapper<SysDict> qw = new QueryWrapper<>();

        String[] pr = {"SFPJ", "YHPJ", "SJXZ", "SFLX", "BJDT", "WDJN", "BJZTSZ", "BZJJN", "YJZK", "TXSP", "WJGL", "TWGL"};
        qw.in("dict_name", Arrays.asList(pr));
        qw.orderByAsc("dict_sort");

        List<SysDict> list = this.baseMapper.selectList(qw);

        for (SysDict o : list) {
            if (!StringUtils.isBlank(o.getDictSubValue())) {
                if ("TWGL".equals(o.getDictName()) || "WJGL".equals(o.getDictName()) || "TXSP".equals(o.getDictName()) || "YJZK".equals(o.getDictName())
                        || "BZJJN".equals(o.getDictName()) || "BJDT".equals(o.getDictName())) {
                    System.out.println(o.getDictSubValue() + "json=======================");
                    Map<String, Object> map = JSONUtil.parseObj(o.getDictSubValue());
                    o.setDictSubValueMap(map);
                } else {
                    System.out.println(o.getDictSubValue() + "============================");
                    JSONArray dictSubList = JSONUtil.parseArray(o.getDictSubValue());
                    o.getDictSubValueList().addAll(JSONUtil.toList(dictSubList, Map.class));
                }
            }
        }

        return list;
    }
}

